package com.csdig.html.controller;

import com.csdig.cms.model.Content;
import com.csdig.cms.service.ContentService;
import com.csdig.cms.utils.PageUtils;
import com.csdig.db.model.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Html页面控制器
 *
 * @author wei_jc
 * @since 1.0.0
 */
@Controller
public class HtmlController {
    public static final String SUB_MENU = "subMenu";
    @Autowired
    private ContentService contentService;

    @RequestMapping(value = "/index")
    public String index() {
        return "index";
    }

    /** ===================== 来投资  =============================== */
    @RequestMapping(value = "/project")
    public String project(Model model) {
        model.addAttribute(SUB_MENU, "touZi");
        return "project";
    }

    @RequestMapping(value = "/project_item")
    public String projectItem(Model model) {
        model.addAttribute(SUB_MENU, "touZi");
        return "project_item";
    }

    @RequestMapping(value = "/project_jie")
    public String projectJie(Model model) {
        model.addAttribute(SUB_MENU, "touZi");
        return "project_jie";
    }

    @RequestMapping(value = "/fund")
    public String fund(Model model) {
        model.addAttribute(SUB_MENU, "touZi");
        return "fund";
    }

    @RequestMapping(value = "/fund_apply")
    public String fundApply(Model model) {
        model.addAttribute(SUB_MENU, "touZi");
        return "fund_apply";
    }

    @RequestMapping(value = "/fund_schema")
    public String fundSchema(Model model) {
        model.addAttribute(SUB_MENU, "touZi");
        return "fund_schema";
    }

    /** ===================== 来理财  =============================== */

    @RequestMapping(value = "/question")
    public String question(Model model) {
        model.addAttribute(SUB_MENU, "liCai");
        return "question";
    }

    @RequestMapping(value = "/member")
    public String member(Model model) {
        model.addAttribute(SUB_MENU, "liCai");
        return "member";
    }

    /** ===================== 来了解  =============================== */

    @RequestMapping(value = "/blog")
    public String blog(Model model, int channelId) throws Exception {
        model.addAttribute(SUB_MENU, "liaoJie");
        Pagination<Content> page = contentService.findAllByPid(channelId, PageUtils.getPageNo(1), PageUtils.getPageSize(20));
        model.addAttribute("page", page);
        Pagination<Content> page1 = contentService.findAllByPid(32, PageUtils.getPageNo(1), PageUtils.getPageSize(20));
        model.addAttribute("jinrong", page1);

        return "blog";
    }

    /** ===================== 来扎堆  =============================== */
    @RequestMapping(value = "/forum")
    public String forum(Model model) {
        model.addAttribute(SUB_MENU, "forum");
        return "forum";
    }

    @RequestMapping(value = "/forum_post")
    public String forumPost(Model model) {
        model.addAttribute(SUB_MENU, "forum");
        return "forum_post";
    }

    /** ===================== 内容  =============================== */
    @RequestMapping(value = "/content")
    public String content(Model model, int contentId) throws Exception {
        Content content = contentService.findById(contentId);
        model.addAttribute("content", content);
        return "content";
    }

    /** ===================== 注册  =============================== */
    @RequestMapping(value = "/reg")
    public String regist() throws Exception {
        return "reg";
    }

    /** ===================== 投资组合  =============================== */
    @RequestMapping(value = "/portfolio")
    public String portfolio() throws Exception {
        return "portfolio";
    }
}
